
//
//  CommentCell.m
//  DaJiang
//
//  Created by sally on 16/10/9.
//  Copyright © 2016年 jiniu. All rights reserved.
//

#import "CommentCell.h"
#import "DateUtil.h"

@interface CommentCell ()

@property (weak, nonatomic) IBOutlet UIImageView *headImage;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *timeWidthLyt;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UILabel *themeLabel;

@end

static CGFloat height = 110;

@implementation CommentCell

- (void)awakeFromNib {
  [self initControl];
}

- (void)initControl {
  self.headImage.layer.cornerRadius = self.headImage.height / 2;
  self.headImage.layer.masksToBounds = YES;
}

+ (CGFloat)cellHeight {
  return height;
}

- (void)setCellData:(CommentModel *)cellData {
  [self.headImage sd_setImageWithURL:[NSURL URLWithString:cellData.user.user_data.user_profile_pic] placeholderImage:[UIImage imageNamed:@"ic_default"]];
  self.nameLabel.text = cellData.user.user_data.user_name;
  self.timeLabel.text = [DateUtil getFormatTime:cellData.updated_at];
  //给时间设置宽度，以确认name的宽度
  self.timeWidthLyt.constant = [self.timeLabel.text sizeWithAttributes:@{NSFontAttributeName : GFontWithSize(GXSmallFontSize)}].width + 2;

  self.contentLabel.text = cellData.op_data.comment;
  self.contentLabel.preferredMaxLayoutWidth = ScreenWidth-GNormalMargin*2;//配合计算包裹高度
  self.themeLabel.text = [NSString stringWithFormat:@"参与话题：%@", cellData.op_data.pro_topic_name];

  //FIXME: 为什么，要+5才能把内容装下
  height = [self.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height+5;
  NSLog(@"height%f",height);
}

@end
